home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / pscheme.init < prev    next >
Text File  |  1999-04-19  |  7KB  |  233 lines

  1. ;;; "pscheme.init" -*-scheme-*-
  2. ;;; SLIB init file for Pocket Scheme
  3. ;;; SLIB orig Author: Aubrey Jaffer (jaffer@ai.mit.edu)
  4. ;;; initial pscheme work for 0.2.3 by Robert Goldman (goldman@htc.honeywell.com)
  5. ;;;
  6. ;;; This code is in the public domain.
  7.  
  8. ; best fit for Windows CE?
  9. (define (software-type) 'MS-DOS)
  10.  
  11. (define (scheme-implementation-type) 'PocketScheme)
  12. (define (scheme-implementation-version) "0.2.5")
  13.  
  14. (define (scheme-implementation-home-page)
  15.   "http://www.angrygraycat.com/scheme/pscheme.htm")
  16.  
  17. (define (implementation-vicinity)
  18.   "\\Program Files\\Pocket Scheme\\")
  19.  
  20. (define (library-vicinity)
  21.   (string-append 
  22.    (implementation-vicinity)
  23.    "slib\\"))
  24.  
  25. (define (home-vicinity)
  26.   "\\My Documents\\")
  27.  
  28. (define *features*
  29.       '(
  30.     source                ;can load scheme source files
  31.                     ;(slib:load-source "filename")
  32. ;    compiled            ;can load compiled files
  33.                     ;(slib:load-compiled "filename")
  34.     rev4-report            ;conforms to
  35. ;    rev3-report            ;conforms to
  36.     ieee-p1178            ;conforms to
  37. ;    sicp                ;runs code from Structure and
  38.                     ;Interpretation of Computer
  39.                     ;Programs by Abelson and Sussman.
  40.     rev4-optional-procedures    ;LIST-TAIL, STRING->LIST,
  41.                     ;LIST->STRING, STRING-COPY,
  42.                     ;STRING-FILL!, LIST->VECTOR,
  43.                     ;VECTOR->LIST, and VECTOR-FILL!
  44. ;    rev2-procedures            ;SUBSTRING-MOVE-LEFT!,
  45.                     ;SUBSTRING-MOVE-RIGHT!,
  46.                     ;SUBSTRING-FILL!,
  47.                     ;STRING-NULL?, APPEND!, 1+,
  48.                     ;-1+, <?, <=?, =?, >?, >=?
  49.     multiarg/and-            ;/ and - can take more than 2 args.
  50.     multiarg-apply            ;APPLY can take more than 2 args.
  51. ;    rationalize
  52. ;    delay                ;has DELAY and FORCE
  53.     with-file            ;has WITH-INPUT-FROM-FILE and
  54.                     ;WITH-OUTPUT-FROM-FILE
  55. ;    string-port            ;has CALL-WITH-INPUT-STRING and
  56.                     ;CALL-WITH-OUTPUT-STRING
  57. ;    transcript            ;TRANSCRIPT-ON and TRANSCRIPT-OFF
  58.     char-ready?
  59. ;    macro                ;has R4RS high level macros
  60. ;    defmacro            ;has Common Lisp DEFMACRO
  61.     eval                ;R5RS two-argument eval
  62. ;    record                ;has user defined data structures
  63. ;    values                ;proposed multiple values
  64.     dynamic-wind            ;proposed dynamic-wind
  65. ;    ieee-floating-point        ;conforms to
  66.     full-continuation        ;can return multiple times
  67. ;    object-hash            ;has OBJECT-HASH
  68.  
  69. ;    sort
  70. ;    queue                ;queues
  71. ;    pretty-print
  72. ;    object->string
  73. ;    format
  74.     trace                ;has macros: TRACE and UNTRACE
  75. ;    compiler            ;has (COMPILER)
  76. ;    ed                ;(ED) is editor
  77.     system                ;posix (system <string>)
  78. ;    getenv                ;posix (getenv <string>)
  79. ;    program-arguments        ;returns list of strings (argv)
  80. ;    Xwindows            ;X support
  81. ;    curses                ;screen management package
  82. ;    termcap                ;terminal description package
  83. ;    terminfo            ;sysV terminal description
  84. ;    current-time            ;returns time in seconds since 1/1/1970
  85.     ))
  86.  
  87. ;;; (OUTPUT-PORT-WIDTH <port>)
  88. (define (output-port-width . arg) 79)
  89.  
  90. ;;; (OUTPUT-PORT-HEIGHT <port>)
  91. (define (output-port-height . arg) 12)
  92.  
  93. ;;; (TMPNAM) makes a temporary file name.
  94. (define tmpnam (let ((cntr 100))
  95.          (lambda () (set! cntr (+ 1 cntr))
  96.              (string-append "slib_" (number->string cntr)))))
  97.  
  98. ;;; (FILE-EXISTS? <string>)
  99. (define (file-exists? f) 
  100.   (let ((file #f))
  101.     (with-handlers (
  102.             ((lambda (x) #t) (lambda (x) #f))
  103.             )
  104.            (set! file (open-input-file f))
  105.            (close-input-port file)
  106.            #t)))
  107.  
  108. ;; pscheme: current-error-port, delete-file, force-output already defined
  109.  
  110. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  111. ;;; port versions of CALL-WITH-*PUT-FILE.
  112.  
  113. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  114. ;;; be returned by CHAR->INTEGER.
  115. (define char-code-limit 256)
  116.  
  117. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  118. (define most-positive-fixnum #x0FFFFFFF)
  119.  
  120. ;;; Return argument
  121. (define (identity x) x)
  122.  
  123. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  124. (define slib:eval eval)
  125.  
  126. ;;; If your implementation provides R4RS macros:
  127. ;; n.b. since pscheme doesn't support qq, slib can't fake it
  128. ;(define macro:eval slib:eval)
  129. ;(define macro:load load)
  130.  
  131. (define *defmacros*
  132.   (list (cons 'defmacro
  133.           (lambda (name parms . body)
  134.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  135.                      *defmacros*))))))
  136. (define (defmacro? m) (and (assq m *defmacros*) #t))
  137.  
  138. (define (macroexpand-1 e)
  139.   (if (pair? e) (let ((a (car e)))
  140.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  141.              (if a (apply (cdr a) (cdr e)) e))
  142.             (else e)))
  143.       e))
  144.  
  145. (define (macroexpand e)
  146.   (if (pair? e) (let ((a (car e)))
  147.           (cond ((symbol? a)
  148.              (set! a (assq a *defmacros*))
  149.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  150.             (else e)))
  151.       e))
  152.  
  153. (define gentemp
  154.   (let ((*gensym-counter* -1))
  155.     (lambda ()
  156.       (set! *gensym-counter* (+ *gensym-counter* 1))
  157.       (string->symbol
  158.        (string-append "slib:G" (number->string *gensym-counter*))))))
  159.  
  160. (define base:eval slib:eval)
  161. (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
  162. (define (defmacro:expand* x)
  163.   (require 'defmacroexpand) (apply defmacro:expand* x '()))
  164.  
  165. (define (slib:eval-load <pathname> evl)
  166.   (if (not (file-exists? <pathname>))
  167.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  168.   (call-with-input-file <pathname>
  169.     (lambda (port)
  170.       (let ((old-load-pathname *load-pathname*))
  171.     (set! *load-pathname* <pathname>)
  172.     (do ((o (read port) (read port)))
  173.         ((eof-object? o))
  174.       (evl o))
  175.     (set! *load-pathname* old-load-pathname)))))
  176.  
  177. (define (defmacro:load <pathname>)
  178.   (slib:eval-load <pathname> defmacro:eval))
  179.  
  180. (define slib:warn
  181.   (lambda args
  182.     (let ((port (current-error-port)))
  183.       (display "Warn: " port)
  184.       (for-each (lambda (x) (display x port)) args))))
  185.  
  186. ;;; define an error procedure for the library
  187. (define slib:error error)
  188.  
  189. ;;; define these as appropriate for your system.
  190. (define slib:tab (integer->char 9))
  191. (define slib:form-feed (integer->char 12))
  192.  
  193. ;;; Support for older versions of Scheme.  Not enough code for its own file.
  194. (define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l))
  195. (define t #t)
  196. (define nil #f)
  197.  
  198. ;;; Define these if your implementation's syntax can support it and if
  199. ;;; they are not already defined.
  200.  
  201. (define (1+ n) (+ n 1))
  202. (define (-1+ n) (+ n -1))
  203. (define 1- -1+)
  204.  
  205. (define in-vicinity string-append)
  206.  
  207. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  208. ;;; return if exitting not supported.
  209. (define slib:exit exit)
  210.  
  211. ;;; Here for backward compatability
  212. (define (scheme-file-suffix) ".scm")
  213.  
  214. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  215. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  216.  
  217. (define (slib:load-source f) (load (string-append f ".scm")))
  218.  
  219. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  220. ;;; by compiling "foo.scm" if this implementation can compile files.
  221. ;;; See feature 'COMPILED.
  222.  
  223. (define slib:load-compiled load)
  224.  
  225. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  226.  
  227. (define slib:load slib:load-source)
  228.  
  229. ;; Hold onto pscheme native version
  230. (define pscheme:require require)
  231.  
  232. (slib:load (in-vicinity (library-vicinity) "require"))
  233.